package com.sec.android.app.myfiles.listener;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.support.v4.content.LocalBroadcastManager;

import com.sec.android.app.myfiles.info.AppConstants;

/**
 * Created by eungho78.lee on 2017-06-13.
 */

public class SmartTipReceiver extends AbsBroadcastReceiverImp {

    private Runnable mTask;

    public SmartTipReceiver(Context context, Runnable task, ListenerMgr.LifeCycle registerTime, ListenerMgr.LifeCycle unregisterTime) {
        super(context, registerTime, unregisterTime);
        mTask = task;
    }

    @Override
    IntentFilter getIntentFilter() {
        return new IntentFilter(AppConstants.CHECK_SMART_TIP);
    }

    @Override
    BroadcastReceiver getBroadcastReceiver() {
        return new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                new Handler(context.getMainLooper()).postDelayed(mTask, 200);
            }
        };
    }

    @Override
    public void registerListener() {
        LocalBroadcastManager.getInstance(mContext).registerReceiver(mReceiver, mIntentFilter);
    }

    @Override
    public void unregisterListener() {
        LocalBroadcastManager.getInstance(mContext).unregisterReceiver(mReceiver);
    }

}
